from ultralytics import YOLO

def validate_model(model_path, data_path):
    # 加载训练好的模型
    model = YOLO(model_path)
    
    # 验证模型
    metrics = model.val(
        data=data_path,  # 数据集配置文件
        split='val',     # 验证集
        imgsz=640,       # 图像大小
        device='0'       # 设备
    )
    
    # 打印验证结果
    print("验证结果:")
    print(f"mAP50-95: {metrics.box.map:.4f}")  # 目标检测的mAP
    print(f"关键点mAP: {metrics.kpt.map:.4f}")  # 关键点检测的mAP

if __name__ == "__main__":
    # 模型路径（训练后会保存在runs/pose/train/weights/best.pt）
    model_path = "runs/pose/train/weights/best.pt"
    # 数据集配置文件
    data_path = "card_corner_dataset/data.yaml"
    
    validate_model(model_path, data_path)
    